import 'package:flutter_mvvm/service/rxNet/rxDartFrame.dart';

class RxdartDio {
  static newPostDio(cb){
    RxDio<String>()
      ..setBaseUrl("http://39.100.255.159:8080/")
      ..setPath("api/auth/login")
      ..setMethord(REQUEST_METHORD.POST)
      ..setParams({
        "mobile": '15566778899',
        "password": 'BS123456',
        "clientId": 'e84bfe28bea7a909567423d38ea1de5d',
        "shopId": ''
      })
      ..setCacheMode(CacheMode.NO_CACHE) //是否走缓存，post请求无需走缓存
      ..call(cb);
  }
  //URL 与 path 可与 api.dart 联动
  static postDio() {
    RxDio<String>()
      ..setBaseUrl("http://39.100.255.159:8080/")
      ..setPath("api/auth/login")
      ..setMethord(REQUEST_METHORD.POST)
      ..setParams({
        "mobile": '15566778899',
        "password": 'BS123456',
        "clientId": 'e84bfe28bea7a909567423d38ea1de5d',
        "shopId": ''
      })
      ..setCacheMode(CacheMode.NO_CACHE) //是否走缓存，post请求无需走缓存
      ..call(
        new NetCallback(
          onCacheFinish: (data) {
            print("缓存回调：" + data);
          },
          onNetFinish: (data) {
            print("网络回调：" + data);
          },
          onUnkownFinish: (data) {
            print("未知回调：" + data);
          },
        ),
      );
  }

  static getDio() {
    RxDio<String>()
      ..setBaseUrl("http://39.100.255.159:8080/")
      ..setPath("api/auth/permissions")
      ..setMethord(REQUEST_METHORD.GET)
      ..setParams({"shopId": '93794b2d12ee48108df2dba21910276f'})
      ..setCacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST) //get请求根据实际情况而定
      ..call(
        new NetCallback(
          onCacheFinish: (data) {
            print("缓存回调：" + data);
          },
          onNetFinish: (data) {
            print("网络回调：" + data);
          },
          onUnkownFinish: (data) {
            print("未知回调：" + data);
          },
        ),
      );
  }
}
